﻿
Imports std

Public Module alllist
    Private Class list
        Public Shared category As [set](Of String) = Nothing
        Public Shared record As [set](Of String) = Nothing
        Public Shared info As [set](Of String) = Nothing

        Shared Sub New()
            category = New [set](Of String)()
            record = New [set](Of String)()
            info = New [set](Of String)()
        End Sub
    End Class

    Private Sub write(ByVal s As [set](Of String), ByVal l As wfileis.data.alllist.list)
        assert(Not s Is Nothing, "s is nothing.")
        assert(Not l Is Nothing, "l is nothing.")

        If set2list(s, l) Then
            If Not l.modify(desttalk) Then
                raiseError("cannot write back to storoom.", errorHandle.errorType.warning)
            End If
        Else
            raiseError("cannot convert set to list.", errorHandle.errorType.warning)
        End If
    End Sub

    Public Sub index()
        assert(Not fulllist Is Nothing, "fulllist is nothing before alllist.index()")

        list.category.clear()
        list.record.clear()
        list.info.clear()

        Dim it As [set](Of String).iterator = Nothing
        it = fulllist.begin()
        While it <> fulllist.end()
            Dim keyprefix As String = Nothing
            Dim storekey As String = Nothing
            Dim type As keytype = keytype.unknown
            type = checkkeytype((+it), keyprefix, storekey)
            If type = keytype.info Then
                list.info.insert(storekey)
            ElseIf type = keytype.category Then
                list.category.insert(storekey)
            ElseIf type = keytype.record Then
                list.record.insert(storekey)
            ElseIf type <> keytype.unknown Then
                assert(False, "should cover all possibilities.")
            End If

            it += 1
        End While

        Dim l As wfileis.data.alllist.list = Nothing
        l = New wfileis.data.alllist.category()
        write(list.category, l)

        l = New wfileis.data.alllist.info()
        write(list.info, l)

        l = New wfileis.data.alllist.record()
        write(list.record, l)
    End Sub
End Module
